package com.example.home.findWork.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.findWork.adapter.HistoryAdapter;
import com.example.home.findWork.bean.HistoryBean;
import com.example.home.tool.OKHttpTool;


public class HistoryFragment extends Fragment {

    private RecyclerView rcvList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_history, container, false);


        rcvList = view.findViewById(R.id.rcv_list);

        getList();

        return view;
    }

    private void getList() {
        OKHttpTool.doNetRequest("prod-api/api/job/deliver/list?pageNum=1&pageSize=8",
            OKHttpTool.GET,
                HistoryBean.class,
            new OKHttpTool.NetCallback() {
                @Override
                public void onSuccess(Object obj) {
                    HistoryBean historyBean = (HistoryBean) obj;
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            bindList(historyBean);
                        }
                    });
                }

                @Override
                public void onFailure(String msg) {

                }
            });
    }

    private void bindList(HistoryBean historyBean) {
        HistoryAdapter historyAdapter = new HistoryAdapter(getActivity(),historyBean.getRows());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        rcvList.setAdapter(historyAdapter);
        rcvList.setLayoutManager(linearLayoutManager);
    }
}